#include "testwebform.h"
#include "ui_testwebform.h"
#include <QDebug>


TestWebForm::TestWebForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TestWebForm)
{
    ui->setupUi(this);
    server=NULL;
    this->resize(1000,800);

    //  ut5.form.setStyleSheet("background-color: gray;");
}

TestWebForm::~TestWebForm()
{
    delete ui;
}

void TestWebForm::on_checkBox_toggled(bool checked)
{
    if( checked ){
        if( !server  ) {
            server = new EchoServer( );
            connect(server, SIGNAL(   signal_readWebCmd( QObject* , QString  )),this, SLOT( readWebCmd(QObject* ,QString)) );
            connect(this, SIGNAL(   signal_writeWebCmd( QObject *,QString  )),server, SLOT( writeWebCmd(QObject *,QString)) );
        }
        server->socketConnect(   ui->lineEdit_ip->text(), ui->spinBox_port->value() );

    }else{
        if(  server  )
            server-> socketDisconnected();
    }
}


void  TestWebForm::readWebCmd( QObject *id, QString cmd  )
{
    //  cmd_to_int( cmd );
    //    switch( cmd ){
    //    case 0:
    //        //read data
    //        break;
    //    case 1:
    //        break;
    //    }
}

//8 + 1 + n
//cmd  =  "CMD45678" + ":" + "data"
//cmd  =  "CMD00001" + ":" + "data"
//cmd  =  "CMD00002" + ":" + "data"
//cmd  =  "CMDxxxxx" + ":" + "data"

void  TestWebForm::writeWebCmd(QObject*id , QString cmd )
{
    //  cmd_to_int( cmd );

    //    switch( cmd ){
    //    case 0:
    //        //read data
    //        break;
    //    case 1:
    //        break;
    //    }
}

void TestWebForm::on_pushButton_send_clicked()
{


}
